package com.funsport.controller.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.funsport.common.PageResult;
import com.funsport.common.Result;
import com.funsport.entity.User;
import com.funsport.service.IUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Tag(name = "Web管理端用户", description = "Web管理端用户管理接口")
@RestController
@RequestMapping("/web/user")
@RequiredArgsConstructor
public class WebUserController {

    private final IUserService userService;

    @Operation(summary = "获取用户列表")
    @PreAuthorize("hasRole('ADMIN')")
    @GetMapping("/list")
    public Result<PageResult<User>> getUserList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "20") Integer pageSize) {
        
        Page<User> pageParam = new Page<>(page, pageSize);
        Page<User> result = userService.page(pageParam);
        
        return Result.success(PageResult.build(
                result.getRecords(), result.getTotal(), page, pageSize));
    }

    @Operation(summary = "获取用户详情")
    @PreAuthorize("hasRole('ADMIN')")
    @GetMapping("/{id}")
    public Result<User> getUserDetail(@PathVariable Long id) {
        return Result.success(userService.getById(id));
    }

    @Operation(summary = "禁用用户")
    @PreAuthorize("hasRole('ADMIN')")
    @PostMapping("/{id}/ban")
    public Result<Void> banUser(@PathVariable Long id) {
        // TODO: 实现禁用用户逻辑
        return Result.success();
    }
}
